<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>vue计算属性方法侦听</title>
  <script src="./vue.js"></script>
</head>
<body>
  <div id="root">
    {{fullName}}
    {{age}}
  </div>
  <script>
    var vm = new Vue({
      el: '#root',
      data: {
        firstName: "claire",
        lastName: "Zhang",
        fullName: "claire Zhang",
        age: 28
      },
      watch: {
        firstName: function() {
          console.log("计算了1次");
          return this.firstName + " " + this.lastName;
        },
        lastName: function() {
          console.log("计算了1次");
          return this.firstName + " " + this.lastName;
        }
      }

      // methods: {
      //   fullName: function() {
      //     console.log("计算了1次");
      //     return this.firstName + " " + this.lastName;
      //   }
      // },

      // 计算属性，依赖的2个值没有改变，只计算一次，有缓存在里面
      // computed: {
      //   fullName: function() {
            // console.log("计算了1次");
      //     return this.firstName + " " + this.lastName
      //   }
      // }

    })
  </script>
</body>
</html>